define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {

		$scope.form.father_id=params.father_id;

		//查询分校信息
		httpService.post(app.urls.unit_selectAttach,{"id":params.id},function(data){
			if("0000" === data.code){
				$scope.unit = data.data[0];
				$scope.findMaster($scope.unit.fk_unit);
			}else{
				alert(data.msg);
			}
		});
		//查询主校区
		httpService.post(app.urls.unit_selectSchool,{status:"0"},function(data){
			if("0000" === data.code){
				$scope.unitList = data.data;
			}else{
				alert(data.msg);
			}
		});
		//查询校长
		$scope.findMaster=function(fk_unit){
			httpService.post(app.urls.teacher_selectByUnit,{"fk_unit":fk_unit},function(data){
				if("0000" === data.code){
					$scope.masterList = data.data;
				}else{
					alert(data.msg);
				}
			});
		}
		//学校办别
		httpService.post(app.urls.dictionary_selectByRule,{fk_rule:"c3547dff15484941b2c1d7b5ab9e65d9"},function(data){
			if("0000" === data.code){
				$scope.bbList = data.data;
			}else{
				alert(data.msg);
			}
		});
		//学校类别
		httpService.post(app.urls.dictionary_selectByRule,{fk_rule:"182c0cbc8924435ab6773779d9f2f48f"},function(data){
			if("0000" === data.code){
				$scope.lbList = data.data;
			}else{
				alert(data.msg);
			}
		});
		//寄宿制
		httpService.post(app.urls.dictionary_selectByRule,{fk_rule:"SJAAAAA10238"},function(data){
			if("0000" === data.code){
				$scope.jsList = data.data;
			}else{
				alert(data.msg);
			}
		});
		//学制
		httpService.post(app.urls.dictionary_selectByRule,{fk_rule:"SJAAAAA100243"},function(data){
			if("0000" === data.code){
				$scope.xzList = data.data;
			}else{
				alert(data.msg);
			}
		});
		//行政区划码
		httpService.post(app.urls.dictionary_selectByRule,{fk_rule:"SJAAAAA33","order_phonetic":"true"},function(data){
			if("0000" === data.code){
				$scope.roadList = data.data;
			}else{
				alert(data.msg);
			}
		});
		//主教语言
		httpService.post(app.urls.dictionary_selectByRule,{fk_rule:"SJAAAAA11"},function(data){
			if("0000" === data.code){
				$scope.zjList = data.data;
			}else{
				alert(data.msg);
			}
		});
		//辅教语言
		httpService.post(app.urls.dictionary_selectByRule,{fk_rule:"SJAAAAA12"},function(data){
			if("0000" === data.code){
				$scope.fjList = data.data;
			}else{
				alert(data.msg);
			}
		});
		$scope.saveForm = function(){
			if($scope.unit.week == '1' && $scope.unit.curricula_time == undefined){
				alert("课表分单双周时，开课时间必填");
				return ;
			}
			if($scope.formCheck()) {
				$scope.form.type=2;
				httpService.post(app.urls.unit_updateUnit,$scope.unit,function(data){
					if("0000" === data.code){
						httpService.post(app.urls.unit_updateAttach,$scope.unit,function(data){
							if("0000" === data.code){
								eventBusService.publish("modules.page.reload",data);
								$scope.goback();
							}else{
								alert(data.msg);
							}
						});
					}else{
						alert(data.msg);
					}
				});
			}
		}
		//返回
		$scope.goback = function(){
			var menu = {};
			menu.url = "modules/content/baseinfo/unit/attach/list/?fk_menuid="+params.fk_menuid+"&father_id="+params.father_id;
			eventBusService.publish("modules.content.load",menu);
		}
		//日期插件
		$('#'+$scope.controllerName+' .datepicker').datepicker({
			onSelect: function(dateText, inst) {
				eval("$scope." + $(this).attr('ng-model') + "='"+$(this).val()+"'");
			}
		});
		$('#'+$scope.controllerName+' .datepicker').datepicker('option', 'dateFormat','yy-mm-dd');//set dateFormat


	}}});